package StudyCode.summary.csv;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class SplitCSVRecord {
	public static void main(String[] args) {
		System.out.println(Arrays.toString(splitCSVToTokens("www,tah1986,com")));
	}

	public static String[] splitCSVToTokens(String line) {
		if (!line.contains("\",") && !line.contains(",\""))
			return line.split(",");
		ArrayList<String> tokenList = new ArrayList<String>();

		String tokens[] = line.split("\",\"");

		for (int i = 0; i < tokens.length; ) {

			{
				tokenList.add(tokens[i].replaceFirst("^\"", "")
						.replaceFirst("\"$", ""));
				i = i + 1;
			}
		}

		String tokenArray[] = tokenList
				.toArray(new String[tokenList.size()]);
		return tokenArray;
	}
}
